<?php

header('Content-Type: text/html; charset=UTF-8');

$rows = array();



$id = isset($_GET['id'])?$_GET['id'] :0;



try {

     $pdo = new PDO('mysql:dbname=study45;host=localhost','root' ,'root');

	 $pdo->query("SET NAMES utf8");

	 //$id = 2;

	 $sql = 'select * from t_student where id=' .$id;

	 $stmt = $pdo->prepare($sql);

	 $flag = $stmt->execute();



	 $rows = $stmt->fetchAll();



	 //var_dump($row);

	 if(!$flag) {

	        echo "error.....";

	}

	} catch (PDOException $e) {

	     echo 'Connection failed: ' . $e->getMessage ();

    }





	?>





<!DOCTYPE html>

<html>

<head>

<meta charset="utf-8" />

<title></title>

</head>



<body>

<div>显示所有学生</div>

<table border="1" style="width:100%">

<tr>

<td>ID</td><td>姓名</td><td>年龄</td><td>性别</td>

</tr>

</table>



<?php foreach($rows as $item) : ?>

<tr>

<td><?php echo $item['id'] ?></td>

<td><?php echo $item['name'] ?></td>

<td><?php echo $item['age'] ?></td>

<td><?php echo $item['gender']==1 ? '男' : '女' ?></td>

</tr>

<?php endforeach ?>



<div>显示所有课程</div>

<table border="1" style="width:100%">

<tr>

<td>ID</td><td>课程</td>

</tr>

</table>



<?php foreach($rows as $item) : ?>

<tr>

<td><?php echo $item['id'] ?></td>

<td><?php echo $item['name'] ?></td>

</tr>

<?php endforeach ?>







<div>显示所有班级</div>

<table border="1" style="width:100%">

<tr>

<td>ID</td><td>班级名</td>

</tr>

</table>



<?php foreach($rows as $item) : ?>

<tr>

<td><?php echo $item['id'] ?></td>

<td><?php echo $item['name'] ?></td>

</tr>

<?php endforeach ?>





<div>显示所有老师</div>

<table border="1" style="width:100%">

<tr>

<td>ID</td><td>老师</td>

</tr>

</table>



<?php foreach($rows as $item) : ?>

<tr>

<td><?php echo $item['id'] ?></td>

<td><?php echo $item['name'] ?></td>

</tr>

<?php endforeach ?>

</body>

</html>
